<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Datafuncoes
 *
 * @author hudson
 */
class Datafuncoes {
  
function validaIp($ip){

	$regex = '/^(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-4])$/';

	if (preg_match($regex, $ip))
        return true;
	else
		return false;

}

function validaData($data) {
	  $var = explode('-',$data);
	  if (($var[1] >= 1) and ($var[0] >= 1) and ($var[2] >= 1)) {
		  $valida = checkdate($var[1],$var[0],$var[2]) ;
	  }
	  else {
		  $valida = 'false' ;
	  }
	return $valida ;
}


function formatDataIng($data) {
	$regex = '/^([0-9]{4})([0-9]{2})-([0-9]{2})$/';
	if ($data == '')
		$dataIng = date("Y-m-d",time());
	else {
		$dataIng = explode("/",$data);
		if (count($dataIng) < 3 )
			$dataIng = explode("-",$data);
		$dataIng = "{$dataIng[2]}-{$dataIng[1]}-{$dataIng[0]}" ;
	}
	return $dataIng ;
}


function formatDataPort($data) {
	if ($data == '')
		$dataIng = date("d-m-Y");
	else {
		$dataIng = explode("/",$data);
		if (count($dataIng) < 3 )
			$dataIng = explode("-",$data);
		$dataIng = "$dataIng[2]-$dataIng[1]-$dataIng[0]" ;
	}
	return $dataIng ;
}

}

?>
